/*
 *  Copyright 2009-2016 Weibo, Inc.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package hao.test.motan.service;

import java.util.Arrays;
import java.util.List;

import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.weibo.api.motan.common.MotanConstants;
import com.weibo.api.motan.util.MotanSwitcherUtil;

import hao.test.motan.api.RestfulService;
import hao.test.motan.api.model.User;

/**
 * Created by zhanglei28 on 2017/8/30.
 */
public class RestfulServerDemo implements RestfulService {
    public static void main(String[] args) throws Exception {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:motan_demo_server_restful.xml");
        MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true);
        System.out.println("restful server start...");
        Thread.sleep(Long.MAX_VALUE);
    }

    public List<User> getUsers(int uid2) {
        return Arrays.asList(new User(uid2, "name" + uid2));
    }

    public String testPrimitiveType() {
        return "helloworld!";
    }

    public Response add(int id, String name) {
        return Response.ok().cookie(new NewCookie("ck", String.valueOf(id))).entity(new User(id, name)).build();
    }

    public Response add2(User user) {
    	return Response.ok().cookie(new NewCookie("ck", String.valueOf("add2"))).entity(user).build();
	}

	public Response add3(int id, String name, User user) {
		System.out.println("id:"+id);
		System.out.println("name:"+name);
		return Response.ok().cookie(new NewCookie("ck", "add3")).entity(user).build();
	}
	public Response add4(Integer id,String name, User user){
		System.out.println("id:"+id);
		System.out.println("name:"+name);
		return Response.ok().cookie(new NewCookie("ck", "add4")).entity(user).build();
	}

	public void testException() {
        throw new UnsupportedOperationException("unsupport");
    }
}
